package com.jida.tijian.handler;

import com.jida.tijian.dto.ResponseObject;
import com.jida.tijian.dto.ResponseObject;
import com.jida.tijian.exception.TijianAPPExceptionEnum;
import com.jida.tijian.exception.TijianAPPException;
import org.apache.commons.logging.LogFactory;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;



@ControllerAdvice //全局异常处理器
public class GlobalExceptionHandler {



    //    //只处理业务异常
    @ResponseBody
    @ExceptionHandler(TijianAPPException.class)
    public ResponseObject handlerTijianAppException(TijianAPPException e){
        e.printStackTrace();
        return new ResponseObject(e.getCode(),e.getMessage());
    }
    //    @ExceptionHandler(TijianAppException.class) //处理括号内的类型异常
//    @ResponseBody  //返回json格式数据给前端
//    public ApiResponse handleTijianAppException(TijianAppException e){
//        e.printStackTrace();
//        System.out.println("异常信息："+e.getStackTrace());
//
//        return new ApiResponse(e.getCode(),e.getMessage());
//
//    }
//
    //处理所有异常
    @ExceptionHandler(Exception.class)
    @ResponseBody  //返回json格式数据给前端
    public ResponseObject handleAllException(Exception e){
        e.printStackTrace();
        //  System.out.println("异常信息："+e.getStackTrace()+",message:"+e.getMessage());
        return new ResponseObject(TijianAPPExceptionEnum.SYSTEM_ERROR.getCode(),TijianAPPExceptionEnum.SYSTEM_ERROR.getMessage());

    }



}


